#ifndef V2_NIM_CONVERSATION_SERVICE_H
#define V2_NIM_CONVERSATION_SERVICE_H
#include "v2_nim_internal.hpp"
namespace v2 {
/// @class V2NIMConversationService
/// @brief 会话服务
/// @pre
/// 调用 `V2NIMClient::get()` 拿到 client 实例
/// 调用 `client.getConversationService()` 拿到 conversationService 实例
/// @par 示例代码
/// @code
/// auto& client = V2NIMClient::get();
/// auto& conversationService = client.getConversationService();
/// @endcode
class V2NIMConversationService {
public:
    /// @brief 创建空会话
    /// @param conversationId 会话 ID
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("account1");
    /// conversationService.createConversation(
    ///     conversationId,
    ///     [](V2NIMConversation conversation) {
    ///         // create succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // create failed, handle error
    ///     });
    /// @endcode
    virtual void createConversation(nstd::string conversationId, V2NIMSuccessCallback<V2NIMConversation> success, V2NIMFailureCallback failure) = 0;

    /// @brief 删除会话
    /// @param conversationId 会话 ID
    /// @param clearMessage 是否清除会话消息
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("account1");
    /// conversationService.deleteConversation(
    ///     conversationId,
    ///     true,
    ///     []() {
    ///         // delete succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // delete failed, handle error
    ///     });
    /// @endcode
    virtual void deleteConversation(nstd::string conversationId,
        bool clearMessage,
        V2NIMSuccessCallback<void> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 批量删除会话
    /// @param conversationIds 会话ID列表
    /// @param clearMessage 是否清除会话消息
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationIds = nstd::vector<nstd::string>();
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account1"));
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account2"));
    /// conversationService.deleteConversationListByIds(
    ///     conversationIds,
    ///     true,
    ///     [](nstd::vector<V2NIMConversationOperationResult> failedList) {
    ///         // delete succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // delete failed, handle error
    ///     });
    /// @endcode
    virtual void deleteConversationListByIds(nstd::vector<nstd::string> conversationIds,
        bool clearMessage,
        V2NIMSuccessCallback<nstd::vector<V2NIMConversationOperationResult>> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 置顶会话
    /// @param conversationId 会话 ID
    /// @param stickTop 是否置顶
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("account1");
    /// conversationService.stickTopConversation(
    ///     conversationId,
    ///     true,
    ///     []() {
    ///         // stick top succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // stick top failed, handle error
    ///     });
    /// @endcode
    virtual void stickTopConversation(nstd::string conversationId,
        bool stickTop,
        V2NIMSuccessCallback<void> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 更新会话
    /// @param conversationId 会话 ID
    /// @param updateInfo 更新参数
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("account1");
    /// V2NIMConversationUpdate updateInfo;
    /// updateInfo.serverExtension = "serverExtension";
    /// conversationService.updateConversation(
    ///     conversationId,
    ///     updateInfo,
    ///     []() {
    ///         // update succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // update failed, handle error
    ///     });
    /// @endcode
    virtual void updateConversation(nstd::string conversationId,
        V2NIMConversationUpdate updateInfo,
        V2NIMSuccessCallback<void> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 更新会话本地扩展
    /// @param conversationId 会话 ID
    /// @param localExtension 本地扩展
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("account1");
    /// conversationService.updateConversationLocalExtension(
    ///     conversationId,
    ///     "localExtension",
    ///     []() {
    ///         // update succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // update failed, handle error
    ///     });
    /// @endcode
    virtual void updateConversationLocalExtension(nstd::string conversationId,
        nstd::string localExtension,
        V2NIMSuccessCallback<void> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 获取会话
    /// @param conversationId 会话 ID
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("account1");
    /// conversationService.getConversation(
    ///     conversationId,
    ///     [](V2NIMConversation conversation) {
    ///         // get conversation succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get conversation failed, handle error
    ///     });
    /// @endcode
    virtual void getConversation(nstd::string conversationId, V2NIMSuccessCallback<V2NIMConversation> success, V2NIMFailureCallback failure) = 0;

    /// @brief 分页获取会话列表
    /// @param offset 分页偏移, 首页传 0, 后续拉取采用上一次返还的 offset
    /// @param limit 分页数量
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// conversationService.getConversationList(
    ///     lastCursor,
    ///     10,
    ///     [](V2NIMConversationResult result) {
    ///         // get conversation list succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get conversation list failed, handle error
    ///     });
    /// @endcode
    virtual void getConversationList(uint64_t offset,
        uint32_t limit,
        V2NIMSuccessCallback<V2NIMConversationResult> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 根据会话ID获取会话列表
    /// @param conversationIds 会话ID列表
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationIds = nstd::vector<nstd::string>();
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account1"));
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account2"));
    /// conversationService.getConversationListByIds(
    ///     conversationIds,
    ///     [](nstd::vector<V2NIMConversation> conversationList) {
    ///         // get conversation list succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get conversation list failed, handle error
    ///     });
    /// @endcode
    virtual void getConversationListByIds(nstd::vector<nstd::string> conversationIds,
        V2NIMSuccessCallback<nstd::vector<V2NIMConversation>> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 根据条件筛选分页获取会话列表
    /// @param offset 分页偏移, 首页传 0, 后续拉取采用上一次返还的 offset
    /// @param limit 分页数量
    /// @param option 查询参数
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// V2NIMConversationOption option;
    /// option.onlyUnread = true;
    /// option.conversationTypes = {V2NIM_CONVERSATION_TYPE_P2P, V2NIM_CONVERSATION_TYPE_TEAM};
    /// conversationService.getConversationListByOption(
    ///     lastCursor,
    ///     10,
    ///     option,
    ///     [](V2NIMConversationResult result) {
    ///         // get conversation list succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get conversation list failed, handle error
    ///     });
    /// @endcode
    virtual void getConversationListByOption(uint64_t offset,
        uint32_t limit,
        V2NIMConversationOption option,
        V2NIMSuccessCallback<V2NIMConversationResult> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 获取会话未读总数
    /// @param conversationId 会话 ID
    /// @return uint32_t 未读总数
    /// @par 示例代码
    /// @code
    /// auto totalUnreadCount = conversationService.getTotalUnreadCount();
    /// @endcode
    virtual uint32_t getTotalUnreadCount() = 0;

    /// @brief 根据会话 ID 列表获取未读总数
    /// @param conversationIds 会话 ID 列表
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationIds = nstd::vector<nstd::string>();
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account1"));
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account2"));
    /// conversationService.getUnreadCountByIds(
    ///     conversationIds,
    ///     [](uint32_t count) {
    ///         // get unread count succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get unread count failed, handle error
    ///     });
    /// @endcode
    virtual void getUnreadCountByIds(nstd::vector<nstd::string> conversationIds,
        V2NIMSuccessCallback<uint32_t> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 根据过滤条件获取会话未读总数
    /// @param filter 过滤条件
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// V2NIMConversationFilter filter;
    /// filter.conversationTypes = {V2NIM_CONVERSATION_TYPE_P2P, V2NIM_CONVERSATION_TYPE_TEAM};
    /// conversationService.getUnreadCountByFilter(
    ///     filter,
    ///     [](uint32_t count) {
    ///         // get unread count succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get unread count failed, handle error
    ///     });
    /// @endcode
    virtual void getUnreadCountByFilter(V2NIMConversationFilter filter, V2NIMSuccessCallback<uint32_t> success, V2NIMFailureCallback failure) = 0;

    /// @brief 清除会话总未读数
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// conversationService.clearTotalUnreadCount(
    ///     []() {
    ///         // clear total unread count succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // clear total unread count failed, handle error
    ///     });
    /// @endcode
    virtual void clearTotalUnreadCount(V2NIMSuccessCallback<void> success, V2NIMFailureCallback failure) = 0;

    /// @brief 根据会话 ID 列表清除会话未读数
    /// @param conversationIds 会话 ID 列表
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// auto conversationIds = nstd::vector<nstd::string>();
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account1"));
    /// conversationIds.emplace_back(V2NIMConversationIdUtil::p2pConversationId("account2"));
    /// conversationService.clearUnreadCountByIds(
    ///     conversationIds,
    ///     [](nstd::vector<V2NIMConversationOperationResult> failedList) {
    ///         // clear unread count succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // clear unread count failed, handle error
    ///     });
    /// @endcode
    virtual void clearUnreadCountByIds(nstd::vector<nstd::string> conversationIds,
        V2NIMSuccessCallback<nstd::vector<V2NIMConversationOperationResult>> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 根据会话类型清除会话未读数
    /// @param conversationTypes
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// conversationService.clearUnreadCountByTypes(
    ///     {V2NIM_CONVERSATION_TYPE_P2P, V2NIM_CONVERSATION_TYPE_TEAM},
    ///     []() {
    ///         // clear unread count succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // clear unread count failed, handle error
    ///     });
    /// @endcode
    virtual void clearUnreadCountByTypes(nstd::vector<V2NIMConversationType> conversationTypes,
        V2NIMSuccessCallback<void> success,
        V2NIMFailureCallback failure) = 0;

    /// @brief 根据会话分组清除会话未读数
    /// @param groupId 会话分组 ID
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @return void
    /// @par 示例代码
    /// @code
    /// conversationService.clearUnreadCountByGroupId(
    ///     "groupId",
    ///     []() {
    ///         // clear unread count succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // clear unread count failed, handle error
    ///     });
    /// @endcode
    virtual void clearUnreadCountByGroupId(nstd::string groupId, V2NIMSuccessCallback<void> success, V2NIMFailureCallback failure) = 0;

    /// @brief 订阅指定过滤条件的会话未读数
    /// @param filter 过滤条件
    /// @return nstd::optional<V2NIMError>
    /// @par 示例代码
    /// @code
    /// V2NIMConversationFilter filter;
    /// filter.conversationTypes = {V2NIM_CONVERSATION_TYPE_P2P, V2NIM_CONVERSATION_TYPE_TEAM};
    /// auto error = conversationService.subscribeUnreadCountByFilter(filter);
    /// if (error) {
    ///     // subscribe failed, handle error
    /// }
    /// @endcode
    virtual nstd::optional<V2NIMError> subscribeUnreadCountByFilter(V2NIMConversationFilter filter) = 0;

    /// @brief 取消订阅指定过滤条件的会话未读数
    /// @param filter 过滤条件
    /// @return nstd::optional<V2NIMError>
    /// @par 示例代码
    /// @code
    /// auto error = conversationService.unsubscribeUnreadCountByFilter(filter);
    /// if (error) {
    ///     // unsubscribe failed, handle error
    /// }
    /// @endcode
    virtual nstd::optional<V2NIMError> unsubscribeUnreadCountByFilter(V2NIMConversationFilter filter) = 0;

    /// @brief 标记会话已读时间戳
    /// @param conversationId 要标记的会话 ID
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @par 示例代码
    /// @code
    /// conversationService.markConversationRead(
    ///     "conversationId",
    ///     []() {
    ///         // mark conversation read succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // mark conversation read failed, handle error
    ///     )};
    /// @endcode
    virtual void markConversationRead(nstd::string conversationId, V2NIMSuccessCallback<time_t> success, V2NIMFailureCallback failure) = 0;

    /// @brief 获取会话已读时间戳
    /// @param conversationId 要获取的会话 ID
    /// @param success 成功回调
    /// @param failure 失败回调
    /// @par 示例代码
    /// @code
    /// conversationService.getConversationReadTime(
    ///     "conversationId",
    ///     [](time_t readTime) {
    ///         // get conversation read time succeeded
    ///     },
    ///     [](V2NIMError error) {
    ///         // get conversation read time failed, handle error
    ///     )};
    /// @endcode
    virtual void getConversationReadTime(nstd::string conversationId, V2NIMSuccessCallback<time_t> success, V2NIMFailureCallback failure) = 0;

    /// @brief 添加会话监听
    /// @param listener 会话监听
    /// @return void
    /// @par 示例代码
    /// @code
    /// V2NIMConversationListener listener;
    /// listener.onSyncStarted = []() {
    ///     // handle conversation sync start event
    /// };
    /// listener.onSyncFinished = []() {
    ///     // handle conversation sync finish event
    /// };
    /// listener.onSyncFailed = [](V2NIMError error) {
    ///     // handle conversation sync failed event
    /// };
    /// listener.onConversationCreated = [](V2NIMConversation conversation) {
    ///     // handle conversation created event
    /// };
    /// listener.onConversationDeleted = [](nstd::vector<nstd::string> conversationIds) {
    ///     // handle conversation deleted event
    /// };
    /// listener.onConversationChanged = [](nstd::vector<V2NIMConversation> conversationList) {
    ///     // handle conversation changed event
    /// };
    /// listener.onTotalUnreadCountChanged = [](uint32_t unreadCount) {
    ///     // handle total unread count changed event
    /// };
    /// listener.onUnreadCountChangedByFilter = [](V2NIMConversationFilter filter, uint32_t unreadCount) {
    ///     // handle unread count changed by group event
    /// };
    /// conversationService.addConversationListener(listener);
    /// @endcode
    virtual void addConversationListener(V2NIMConversationListener listener) = 0;

    /// @brief 移除会话监听
    /// @param listener 会话监听
    /// @return void
    /// @par 示例代码
    /// @code
    /// V2NIMConversationListener listener;
    /// // ...
    /// conversationService.addConversationListener(listener);
    /// // ...
    /// conversationService.removeConversationListener(listener);
    /// @endcode
    virtual void removeConversationListener(V2NIMConversationListener listener) = 0;
};
}  // namespace v2

#endif
